﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc
{
    public partial class ChangePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Message.Text = "·密码为6～20位字母、数字组合，注意两次输入的新密码要一致";
        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            object uid=Session["OperatorID"];
            if(uid==null)
            {
                this.Message.Text = "·你还没登录系统！";
                return;
            }
            if (this.Pwd1.Text=="")
            {
                this.Message.Text = "·请输入原密码！";
            }
            else if (this.Pwd2.Text != this.Pwd3.Text)
            {
                this.Message.Text = "·两次输入的新密码不一致！";
            }
            else if (this.Pwd1.Text.Length > 20 || this.Pwd2.Text.Length > 20 || this.Pwd2.Text.Length < 6)
            {
                this.Message.Text = "·密码长度不符！";
            }
            else
            {
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;
                Cmd.CommandText = "update [操作员] set [密码]='" + this.Pwd2.Text.Replace("'", "''") + "' where [工号]=" + (string)uid + " and [密码]='" + this.Pwd1.Text.Replace("'", "''") + "'";
                //Cmd.CommandType = CommandType.Text;
                int lines = Cmd.ExecuteNonQuery();
                Cmd.Dispose();
                Cmd.Dispose();
                Conn.Close();
                Conn.Dispose();
                if (lines == 0)
                {
                    this.Message.Text = "·修改密码失败，可能是原密码有误！";
                }
                else
                {
                    this.Message.Text = "·修改密码成功！";
                }
            }

        }
    }
}
